jeeps/gpsmem.h jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h \
garmin_tables.h grtcirc.h
geo.o: geo.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
- cet.h cet_util.h inifile.h session.h src/core/datetime.h
+ cet.h cet_util.h inifile.h session.h src/core/datetime.h src/core/file.h
geoniche.o: geoniche.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
pdbfile.h jeeps/gpsmath.h jeeps/gps.h jeeps/gpsport.h \
jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h \
- src/core/xmlstreamwriter.h
+ src/core/xmlstreamwriter.h src/core/file.h
grtcirc.o: grtcirc.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
grtcirc.h
cet.h cet_util.h inifile.h session.h src/core/datetime.h csv_util.h
kml.o: kml.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
cet.h cet_util.h inifile.h session.h src/core/datetime.h xmlgeneric.h \
- grtcirc.h src/core/xmlstreamwriter.h
+ grtcirc.h src/core/xmlstreamwriter.h src/core/file.h
lmx.o: lmx.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
cet.h cet_util.h inifile.h session.h src/core/datetime.h xmlgeneric.h
lowranceusr.o: lowranceusr.cc defs.h config.h queue.h zlib/zlib.h \
xhtmlent.o: xhtmlent.cc
xmlgeneric.o: xmlgeneric.cc defs.h config.h queue.h zlib/zlib.h \
zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h session.h \
- src/core/datetime.h xmlgeneric.h
+ src/core/datetime.h xmlgeneric.h src/core/file.h
xmltag.o: xmltag.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h
xol.o: xol.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
static gbfile* ofd;
-#include <QtCore/QFile>
#include <QtCore/QXmlStreamReader>
#include <QtCore/QXmlStreamWriter>
#include <QtCore/QDebug>
+#include "src/core/file.h"
QString ostring;
QXmlStreamWriter writer(&ostring);
static void
geo_read(void)
{
- QFile file(geo_read_fname);
+ gpsbabel::File file(geo_read_fname);
file.open(QIODevice::ReadOnly);
reader.setDevice(&file);
#include <expat.h>
static XML_Parser psr;
#endif
+#include "src/core/file.h"
#include "src/core/xmlstreamwriter.h"
-#include <QtCore/QFile>
#include <QtCore/QRegExp>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
static int cache_descr_is_html;
static gbfile* fd;
static const char* input_fname;
-static gbfile* ofd = NULL;
-static QFile* oqfile;
+static gpsbabel::File* oqfile;
static gpsbabel::XmlStreamWriter* writer;
static short_handle mkshort_handle;
static const char* link_url;
{
mkshort_handle = NULL;
// QFile requires binary mode on Windows.
- ofd = gbfopen(fname, "wb", MYNAME);
- oqfile = new QFile;
- oqfile->open(ofd->handle.std, QIODevice::WriteOnly);
+ oqfile = new gpsbabel::File(fname);
+ oqfile->open(QIODevice::WriteOnly);
writer = new gpsbabel::XmlStreamWriter(oqfile);
writer->setAutoFormattingIndent(2);
oqfile->close();
delete oqfile;
oqfile = NULL;
- gbfclose(ofd);
- ofd = NULL;
mkshort_del_handle(&mkshort_handle);
}
#include "xmlgeneric.h"
#include "grtcirc.h"
+#include "src/core/file.h"
#include "src/core/xmlstreamwriter.h"
// options
static const char* posnfilename;
static char* posnfilenametmp;
-static gbfile* ofd = NULL;
-static QFile* oqfile;
+static gpsbabel::File* oqfile;
static gpsbabel::XmlStreamWriter* writer;
typedef enum {
/*
* Reduce race conditions with network read link.
*/
- ofd = gbfopen(fname, "w", MYNAME);
- oqfile = new QFile;
- oqfile->open(ofd->handle.std, QIODevice::WriteOnly);
+ oqfile = new gpsbabel::File(fname);
+ oqfile->open(QIODevice::WriteOnly);
writer = new gpsbabel::XmlStreamWriter(oqfile);
writer->setAutoFormattingIndent(2);
oqfile->close();
delete oqfile;
oqfile = NULL;
- gbfclose(ofd);
- ofd = NULL;
if (posnfilenametmp) {
#if __WIN32__
--- /dev/null
+Cannot open './reference/doesnotexist' for read. Error was 'No such file or directory'.
--- /dev/null
+/*
+ Copyright (C) 2013 Robert Lipe, gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include <QtCore/QFile>
+#include <QtCore/QIODevice>
+#include <stdio.h>
+#include "defs.h"
+
+// Mimic gbfile open services
+
+namespace gpsbabel
+{
+
+class File : public QFile
+{
+public:
+ File(const QString& s) : QFile(s) {}
+
+ /* in the tradition of gbfile we assume WriteOnly or ReadOnly, not ReadWrite */
+ bool open(OpenMode mode) {
+ bool status;
+
+ if (QFile::fileName() == "-") {
+ if (mode & QIODevice::WriteOnly) {
+ status = QFile::open(stdout, mode);
+ } else {
+ status = QFile::open(stdin, mode);
+ }
+ } else {
+ status = QFile::open(mode);
+ }
+
+ if (!status) {
+ fatal("Cannot open '%s' for %s. Error was '%s'.\n",
+ CSTR(QFile::fileName()),
+ mode == QIODevice::WriteOnly? "write" : "read",
+ CSTR(QFile::errorString()));
+ }
+ return status;
+ }
+
+};
+
+}; // namespace gpsbabel
rm -f ${TMPDIR}/gl.loc
gpsbabel -i geo -f ${REFERENCE}/../geocaching.loc -o geo -F ${TMPDIR}/gl.loc
compare ${TMPDIR}/gl.loc ${REFERENCE}
+
+# we have a one off reader in geo, make sure it can read stdin.
+rm -f ${TMPDIR}/gl_si.loc
+cat ${REFERENCE}/../geocaching.loc | gpsbabel -i geo -f - -o geo -F ${TMPDIR}/gl_si.loc
+compare ${TMPDIR}/gl_si.loc ${REFERENCE}/gl.loc
# Read, write GPX file with times that don't fit in time_t, subsecond.
gpsbabel -i gpx -f ${REFERENCE}/bigtime.gpx -o gpx -F ${TMPDIR}/bigtime.gpx
compare ${REFERENCE}/bigtime.gpx ${TMPDIR}/bigtime.gpx
+
+# test standard output
+rm -f ${TMPDIR}/basecamp~gpx_so.gpx
+gpsbabel -i gpx -f ${REFERENCE}/basecamp.gpx -o gpx -F - 1> ${TMPDIR}/basecamp~gpx_so.gpx
+compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx_so.gpx
compare ${TMPDIR}/ge-eg-track1.kml ${TMPDIR}/ge-eg-track2.kml
compare ${TMPDIR}/ge-eg-track2.kml ${TMPDIR}/ge-eg-track3.kml
+# test std output
+rm -f ${TMPDIR}/bnds_so.kml
+gpsbabel -i gpx -f ${REFERENCE}/bounds-test.gpx -o kml -F - 1> ${TMPDIR}/bnds_so.kml
+compare ${REFERENCE}/bounds-test.kml ${TMPDIR}/bnds_so.kml
set -e
if which xmllint > /dev/null;
gpsbabel -i xol -f ${REFERENCE}/xol-sample.xol -o gpx -F ${TMPDIR}/xol-sample.gpx
compare ${REFERENCE}/xol-sample.gpx ${TMPDIR}/xol-sample.gpx
+# check xmlgeneric can handle stdin
+rm -f ${TMPDIR}/xol-sample.gpx
+cat ${REFERENCE}/xol-sample.xol | gpsbabel -i xol -f - -o gpx -F ${TMPDIR}/xol-sample.gpx
+compare ${REFERENCE}/xol-sample.gpx ${TMPDIR}/xol-sample.gpx
+
+# check xmlgeneric can detect no input file
+# we expect this to fail
+rm -f ${TMPDIR}/xol-sample_si.gpx
+${PNAME} -i xol -f ${REFERENCE}/doesnotexist -o gpx -F ${TMPDIR}/xol-sample_si.gpx 2> ${TMPDIR}/nonexistent.err && {
+ echo "${PNAME} succeeded! (it shouldn't have with this input...)"
+}
+# check error message is what we expected
+compare ${REFERENCE}/nonexistent.err ${TMPDIR}/nonexistent.err
+
+
gpsbabel -i gpx -f ${REFERENCE}/xol-sample.gpx -o xol -F ${TMPDIR}/xol-sample-gpx.xol
compare ${REFERENCE}/xol-sample-gpx.xol ${TMPDIR}/xol-sample-gpx.xol
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
-#include <QtCore/QFile>
#include <QtCore/QTextCodec>
#include <QtCore/QXmlStreamAttributes>
#include <QtCore/QXmlStreamReader>
#include "defs.h"
#include "xmlgeneric.h"
#include "cet_util.h"
+#include "src/core/file.h"
#define DEBUG_TAG 0
#if DEBUG_TAG
void xml_read(void)
{
- QFile file(rd_fname);
+ gpsbabel::File file(rd_fname);
QString current_tag;
file.open(QIODevice::ReadOnly);